<template>
  <van-goods-action>
    <van-goods-action-icon icon="chat-o" text="客服" color="#ee0a24" />
    <van-goods-action-icon icon="cart-o" text="购物车" @click="toCarts" />
    <van-goods-action-icon icon="star" text="已收藏" color="#ff5000" />
    <van-goods-action-button type="warning" text="加入购物车" @click="buygood" />
    <van-goods-action-button type="danger" text="立即购买" />
  </van-goods-action>
</template>

<script>
import { Dialog, Toast } from "vant";
export default {
  name: "DetailBottom",
  props: {
    addCartsfo: Object,
    default() {
      return {};
    }
  },
  methods: {
		// 商品的加购
    buygood() {
      console.log(this.$store);
      console.log(this.addCartsfo);
      let _self = this;
      let title =
        _self.addCartsfo.title.length > 20
          ? _self.addCartsfo.title.slice(0, 20) + "..."
          : _self.addCartsfo.title;
      console.log(title);
      Dialog.confirm({
        // title: "标题",
        message: "确认加购  [" + title + "]   吗？"
      })
        .then(() => {
          _self.$store.dispatch("asynAddCart", {
            id: _self.addCartsfo.id,
            topImages: _self.addCartsfo.topImages,
            lowNowPrice: _self.addCartsfo.lowNowPrice,
            title: _self.addCartsfo.title
          });
          Toast.success("加购成功！");
        })
        .catch(err => {
          console.log(err);
        });
    },
    // 跳到购物车页面
    toCarts() {
      this.$router.push("/carts"); //可以返回上一页
      // this.$router.replace(this.path)  //替换，不能返回
    }
  }
};
</script>

<style>
</style>
